<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

// {{{ requires
//require_once CLASS_EX_REALDIR . 'page_extends/mypage/LC_Page_AbstractMypage_Ex.php';
require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
/**
 * MyPage のページクラス.
 *
 * @package Page
 * @author LOCKON CO.,LTD.
 * @version $Id: LC_Page_Mypage.php 21981 2012-07-28 14:54:37Z Seasoft $
 */
class LC_Page_MyPage extends LC_Page_Ex {

    // {{{ properties

    /** ページナンバー */
    var $tpl_pageno;

    // }}}
    // {{{ functions

    /**
     * Page を初期化する.
     *
     * @return void
     */
    function init() {
       parent::init();
       
       $this->linkCss[] = 'css/sapaImport.css';
       //引入本页面javascript
	   $this->link_javascript[] = "js/sapa/jquery.dataTables.js";
	    	
       //权限验证
       if($this->objSess->GetSession('cert')!= CERT_STRING){
       		SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, 'is not a certificate authority.');
       }
       
       if($this->objSess->GetSession('authority')== '00'){
       	
       		$this->tpl_mainpage = 'mypage/admin_index.tpl';
			$objQuery = SC_Query::getSingletonInstance();
			$where = 'a.id = b.id and b.title_id = c.id ';
		    $this->userDates = $objQuery->select('*, a.id as id ','mst_users AS  a , tab_person_users AS b, mst_title AS  c ', $where);
		
       }else{
       		$this->tpl_mainpage = 'mypage/index.tpl';
       }
       
    }

    /**
     * Page のプロセス.
     *
     * @return void
     */
    function process() {
        parent::process();
        $this->action();
        $this->sendResponse();
    }

    /**
     * Page のAction.
     *
     * @return void
     */
    function action() {
    	
		$userId = $this->getValFromPostOrGet("userId");
        
		switch ($this->getMode()) {
        	
            case 'showUserInfo':
            	
            	$this->checkUserIdIsNull($userId);
            	//去确认画面
                $this->tpl_mainpage = 'regist/confirm.tpl';
                $this->getUserInfoFromDB($userId);
                break;

            case 'edit':
            	$this->checkUserIdIsNull($userId);
                break;
                
            case 'block':
            	$this->checkUserIdIsNull($userId);
                break;
                
            default:
                break;
        }
    }

    /**
     * デストラクタ.
     *
     * @return void
     */
    function destroy() {
        parent::destroy();
    }
    
    function checkUserIdIsNull($userId){
    	
		if(empty($userId)){
			SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', true, 'User Id Is NULL.');
		}
    }
	function getUserInfoFromDB($userId){
		
		//SelectBox 初期化
    	$masterData = new SC_DB_MasterData();
        $this->locationList = $masterData->getMasterData("mst_location");
    	$this->titleList =$masterData->getMasterData("mst_title");
    	$this->degreeList =$masterData->getMasterData("mst_degree");
    	$this->specialtiesList =$masterData->getMasterData("mst_specialties");
    	$this->stateList =$masterData->getMasterData("mst_state");
    	$this->countryList =$masterData->getMasterData("mst_country");
    	
    	//radioBox 初期化
    	$this->maillingAddressList =$masterData->getMasterData("mst_mailling_type");
    	$this->membershipFeeList =$masterData->getMasterData("mst_membership_fee");
    	
		$objQuery = SC_Query::getSingletonInstance();
	    $rsMst = $objQuery->select('*','mst_users', "id = ?", array($userId));
	    $rsPtb = $objQuery->select('*','tab_person_users', "id = ?", array($userId));
	    
		$this->regist_postVal['mail'] = strtolower(trim($rsMst[0]['mail_add']));
		$this->regist_postVal['password1'] = $rsMst[0]['pass_word'];
		
		$this->regist_postVal['location'] = $rsPtb[0]['location_id'];
		$this->regist_postVal['locationVal'] = $this->locationList[$rsPtb[0]['location_id']];

		GC_Utils_Ex::gfPrintLog('----'.$rsPtb[0]['location_id']);
		GC_Utils_Ex::gfPrintLog('----'.$this->locationList[$rsPtb[0]['location_id']]);
		GC_Utils_Ex::gfPrintLog('----'.$this->regist_postVal['locationVal']);
		
		$this->regist_postVal['title'] = $rsPtb[0]['title_id'];
		$this->regist_postVal['titleVal'] = $this->titleList[$rsPtb[0]['title_id']];
		
		$this->regist_postVal['lastname'] = $rsPtb[0]['lastname'];
		$this->regist_postVal['firstname'] = $rsPtb[0]['firstname'];
		$this->regist_postVal['field_mi'] = $rsPtb[0]['field_mi'];
		
		$this->regist_postVal['nameinchinese'] = $rsPtb[0]['chinese_name'];
		$this->regist_postVal['nameinchineseVal'] = $this->degreeList[$rsPtb[0]['chinese_name']];
		
		$this->regist_postVal['affiliation'] = $rsPtb[0]['affiliation_employer'];
		
		$this->regist_postVal['specialties'] = $rsPtb[0]['specialties_id'];
		$this->regist_postVal['specialtiesVal'] = $this->specialtiesList[$rsPtb[0]['specialties_id']];
		
		$this->regist_postVal['keywords'] = $rsPtb[0]['key_words'];
		
		$this->regist_postVal['mailaddress'] = $rsPtb[0]['mailling_type_id'];
		$this->regist_postVal['mailaddressVal'] = $this->maillingAddressList[$rsPtb[0]['mailling_type_id']];
		
		$this->regist_postVal['street'] = $rsPtb[0]['street'];
		//$this->regist_postVal['line2'] = $rsPtb[0]['line2'];
		$this->regist_postVal['city'] = $rsPtb[0]['city'];
		
		$this->regist_postVal['state'] = $rsPtb[0]['state_id'];
		$this->regist_postVal['stateVal'] = $this->stateList[$rsPtb[0]['state_id']];
		
		$this->regist_postVal['zip'] = $rsPtb[0]['zip_cood'];
		
		$this->regist_postVal['country'] = $rsPtb[0]['country_id'];
		$this->regist_postVal['countryVal'] = $this->countryList[$arrPost['country_id']];
		
		$this->regist_postVal['tel'] = $rsPtb[0]['tel_no'];
		$this->regist_postVal['fax'] = $rsPtb[0]['fax_no'];
		
		$this->regist_postVal['mailmagazine'] = $rsMst[0]['mailmagazine_flg'];
		
		if (trim($this->regist_postVal['mailmagazine']) == MAILMAGA_AGREE_KEY) {
			$this->regist_postVal['mailmagazineVal'] = MAILMAGA_AGREE_VALUE;
			$this->regist_postVal['mailmagazine'] = MAILMAGA_AGREE_KEY;
		}elseif ($this->regist_postVal['mailmagazine'] == MAILMAGA_DISAGREE_KEY){
			$this->regist_postVal['mailmagazineVal'] = MAILMAGA_DISAGREE_VALUE;
			$this->regist_postVal['mailmagazine'] = MAILMAGA_DISAGREE_KEY;
		}
		$this->regist_postVal['mfee'] = $rsMst[0]['member_flg'];
		$this->regist_postVal['mfeeVal'] = $this->membershipFeeList[$rsMst[0]['member_flg']];
	}
	
}
